#include "Material.h"
#include "Engine.h"

// ----------------------------------------------------------------
// Classe Material
// ----------------------------------------------------------------
Material::Material(void)
    : cor(),
      texturaHabilitada(true),
      transparente(true),
      id(0)
{
}
// ----------------------------------------------------------------
Material::~Material(void)
{
    if( id )
    {
        glDeleteTextures( 1, &id);
        id = 0;
    }
}
// ----------------------------------------------------------------
void Material::carregarTextura(const char* arquivoTextura)
{
    if( id )
    {
        glDeleteTextures( 1, &id);
    }

    id = Engine::loadTexture(arquivoTextura);
}
// ----------------------------------------------------------------
void Material::usarMaterial(void)
{
    if( texturaHabilitada )
    {
        glEnable(GL_TEXTURE_2D);
        glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    }else
    {
        glDisable(GL_TEXTURE_2D);
    }

    glBindTexture( GL_TEXTURE_2D, id );

    if( transparente )
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }else
    {

    }

    glColor4f( cor.r, cor.g, cor.b, cor.a );
}
// ----------------------------------------------------------------
